package lanQiaoBei.hash;
/*

布隆过滤器 部分实现
* */
public class BloomFilter {
    private int[]bitmap;

    public BloomFilter(int[] bitmap) {
        this.bitmap = bitmap;
    }
    private void setBitTrue(int hash){
            int index=hash/32;
            int bit=hash%32;
            bitmap[index]=(bitmap[index]|(1<<bit));
    }
    private void setBitFalse(int hash){
            int index=hash/32;
            int bit=hash%32;
            bitmap[index]=bitmap[index] & ~(1<<bit);
    }
    private int getBit(int hash){
            int index=hash/32;
            int bit=hash%32;
            return bitmap[index]>>bit & 1;
    }
    public static void main(String[] args) {
        BloomFilter bloomFilter = new BloomFilter(new int[10]);
        System.out.println(bloomFilter.getBit(199));
        bloomFilter.setBitTrue(199);
        System.out.println(bloomFilter.getBit(199));
    }

}
